package com.imooc.concurrency.example.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
public class newScheduleThreadPoolExample {

    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);

        log.info("main run");
        executorService.schedule(() -> {
            log.warn("schedule run");
        }, 3, TimeUnit.SECONDS);

        executorService.scheduleAtFixedRate(() -> {
            log.warn("循环执行");
        }, 1, 3, TimeUnit.SECONDS);

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                log.warn("timer run");
            }
        }, 0, 5*1000);
    }
}
